package cn.wildfirechat.app.jpa;

import lombok.Data;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import javax.persistence.Table;
import java.time.LocalDateTime;

@RepositoryRestResource()
public interface PCLoginRepository extends CrudRepository<PCLogin, Long> {
    @Query(value = "SELECT * FROM pc_login WHERE owner_id = ?1 AND status = 1 AND STR_TO_DATE(end_time, '%Y-%m-%d') > DATE(?2) ORDER BY STR_TO_DATE(end_time, '%Y-%m-%d') DESC LIMIT 1", nativeQuery = true)
    PCLogin findByOwnerId(String userId, LocalDateTime now);
}
